<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui"
	xmlns:s="http://sduept.security.el/func"
	template="/template/template_dialog.xhtml">
	<ui:define name="head">
		<title>问题反馈</title>
	</ui:define>
	<ui:define name="content">
		<p:confirmDialog global="true" showEffect="fade" hideEffect="fade">
			<p:commandButton value="是" type="button"
				styleClass="ui-confirmdialog-yes" icon="ui-icon-check" />
			<p:commandButton value="否" type="button"
				styleClass="ui-confirmdialog-no" icon="ui-icon-close" />
		</p:confirmDialog>
		<div style="margin-left: 10px;">
			<h:form id="form">
				<p:growl id="msgs" showDetail="true" />
				<div class="box-header">
					<p:outputLabel value="提出时间：" />
					<p:calendar id="popup1" navigator="true" size="12"
						value="#{problemFeedbackController.queryDate1}"
						pattern="yyyy-MM-dd" maxdate="Date()">
					</p:calendar>
					<p:outputLabel for="popup2" value="至 " style="margin-right:5px;margin-left:5px" />
					<p:calendar id="popup2" navigator="true" style="margin-right:15px" size="12"
						value="#{problemFeedbackController.queryDate2}"
						pattern="yyyy-MM-dd" maxdate="Date()" locale="zh">
					</p:calendar>
					<p:outputLabel value="模块：" />
					<p:autoComplete id="module" dropdown="true" size="15"
						placeholder="输入首字母查询" scrollHeight="400"
						value="#{problemFeedbackController.selectModule}"
						style="margin-right:10px;"
						completeMethod="#{problemFeedbackController.completeModule}">
					</p:autoComplete>
					<p:outputLabel value="处理人员：" />
					<p:autoComplete id="solver" dropdown="true" size="15"
						placeholder="首字母查询" scrollHeight="400"
						value="#{problemFeedbackController.solver}"
						style="margin-right:10px;"
						completeMethod="#{problemFeedbackController.completeSolver}">
					</p:autoComplete>
					<p:outputLabel value="处理情况：" />
					<h:selectOneMenu value="#{problemFeedbackController.handleState}"
						style="width:120px;margin-right:20px;height:30px">
						<f:selectItem itemLabel="待处理" itemValue="待处理" />
						<f:selectItem itemLabel="全部" itemValue="" />
						<f:selectItem itemLabel="处理中" itemValue="处理中" />
						<f:selectItem itemLabel="已处理" itemValue="已处理" />
					</h:selectOneMenu>
					<p:commandButton value="查询"
						actionListener="#{problemFeedbackController.search}"
						icon="ui-icon-search" update="form:dataTable" />
				</div>
				<p:toolbar id="toolbar">
					<f:facet name="left">
						<p:commandButton value="新建" icon="fa fa-plus"
							oncomplete="PF('createDlg').show()"
							actionListener="#{problemFeedbackController.preCreate()}"
							update="form:createDlg " />
						<p:commandButton value="编辑" id="editbtn" icon="fa fa-pencil"
							disabled="#{problemFeedbackController.selectProblemFeedback.id == null}"
							oncomplete="PF('createDlg').show()"
							actionListener="#{problemFeedbackController.preUpate()}"
							update="form:createDlg " />
						<p:commandButton value="删除" id="delbtn" icon="fa fa-trash"
							disabled="#{problemFeedbackController.selectProblemFeedback.id == null}"
							update="form:dataTable form:delbtn form:editbtn form:msgs"
							actionListener="#{problemFeedbackController.delete()}">
							<p:confirm header="提示" message="确定删除该记录吗?" icon="ui-icon-alert" />
						</p:commandButton>
						<p:commandButton value="导出" icon="ui-icon-document"
							actionListener="#{problemFeedbackController.exportProblemFeedback()}"
							ajax="false">
							<p:fileDownload value="#{problemFeedbackController.exportFile}" />
						</p:commandButton>
					</f:facet>
				</p:toolbar>
				<p:dataTable var="item" id="dataTable"
					value="#{problemFeedbackController.problemFeedbacks}"
					selection="#{problemFeedbackController.selectProblemFeedback}"
					rowKey="#{item.id}" emptyMessage="无记录" selectionMode="single"
					paginator="true" paginatorPosition="bottom"
					paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
					rows="10" rowsPerPageTemplate="10,20,50" rowIndexVar="index">
					<p:ajax event="rowSelect"
						update="form:delbtn form:editbtn form:dataTable " />
					<p:ajax event="rowUnselect"
						update="form:delbtn form:editbtn form:dataTable " />
					<p:column headerText="序号 " width="3%">
						<h:outputText value="#{index+1}" />
					</p:column>
					<p:column headerText="模块" width="5%">
						<h:outputText value="#{item.module}" />
					</p:column>
					<p:column headerText="问题描述" width="12%">
						<h:outputText value="#{item.description}" />
					</p:column>
					<p:column headerText="问题分类" width="5%">
						<h:outputText value="#{item.category}" />
					</p:column>
					<p:column headerText="提出时间" width="5%">
						<h:outputText value="#{item.proposeTime}">
							<f:convertDateTime pattern="yyyy-MM-dd" />
						</h:outputText>
					</p:column>
					<p:column headerText="提出人员" width="5%">
						<h:outputText value="#{item.proposer}" />
					</p:column>
					<p:column headerText="通知时间" width="5%">
						<h:outputText value="#{item.notifyTime}">
							<f:convertDateTime pattern="yyyy-MM-dd" />
						</h:outputText>
					</p:column>
					<p:column headerText="通知人员" width="5%">
						<h:outputText value="#{item.notifier}" />
					</p:column>
					<p:column headerText="计划完成时间" width="5%">
						<h:outputText value="#{item.planFinishTime}">
							<f:convertDateTime pattern="yyyy-MM-dd" />
						</h:outputText>
					</p:column>
					<p:column headerText="处理时间" width="5%">
						<h:outputText value="#{item.solveTime}">
							<f:convertDateTime pattern="yyyy-MM-dd" />
						</h:outputText>
					</p:column>
					<p:column headerText="处理人员" width="5%">
						<h:outputText value="#{item.solver}" />
					</p:column>
					<p:column headerText="原因" width="10%">
						<h:outputText value="#{item.problemReason}" />
					</p:column>
					<p:column headerText="处理过程" width="10%">
						<h:outputText value="#{item.handleProcess}" />
					</p:column>
					<p:column headerText="处理情况" width="5%">
						<h:outputText value="#{item.handleState}" />
					</p:column>
					<p:column headerText="备注" width="5%">
						<h:outputText value="#{item.remark}" />
					</p:column>
					<p:column width="5%" headerText="附件" selectRow="false">
						<p:rowExpansion>
							<p:repeat value="#{problemFeedbackController.getFileNamesByProblemFeedbackId(item.id)}" var="file"  rendered="#{problemFeedbackController.getFileNamesByProblemFeedbackId(item.id).size() != 0}" >
								<div class="row" style="padding-left: 10px;">
									<p:commandLink title="删除" style="margin-right:5px;float:left;"
										styleClass="ui-icon ui-icon-trash" update="form:dataTable form:msgs"
										actionListener="#{problemFeedbackController.removeFile(file)}">
										<p:confirm header="提示" message="确定删除该记录吗?" icon="ui-icon-alert" />
									</p:commandLink>
									<p:commandLink title="下载" oncomplete="downloadFunc()"
										styleClass="ui-icon ui-icon-arrowthick-1-s"
										actionListener="#{problemFeedbackController.fileDownloadView(file.id)}"
										style="margin-right:5px;float:left;" update="downloadForm:fileExist form:msgs">
									</p:commandLink>
									<p:commandLink oncomplete="downloadFunc()"
										actionListener="#{problemFeedbackController.fileDownloadView(file.id)}"
										style="word-break:break-all;margin-right:5px;float:left;" >
										<span>#{file.description}</span>
									</p:commandLink>
								</div>
							</p:repeat>
						</p:rowExpansion>
					</p:column>
					<p:column width="5%" style="text-align: center">
						<p:commandButton title="上传附件" icon="ui-icon-arrowreturnthick-1-n"
							oncomplete="PF('uploadFileDlg').show()"
							actionListener="#{problemFeedbackController.preUpLoadFile(item.id)}" />
					</p:column>
				</p:dataTable>
				<p:dialog widgetVar="createDlg"
					header="#{problemFeedbackController.selectProblemFeedback.id==null?'新建':'编辑'}"
					modal="true" id="createDlg" width="750" height="650">
					<p:toolbar>
						<f:facet name="left">
							<p:commandButton id="createSaveBtn" value="保存"
								style="float: right;" icon="fa fa-floppy-o"
								update="form:dataTable form:msgs form:delbtn form:editbtn form:module"
								actionListener="#{problemFeedbackController.save()}"
								oncomplete="PF('createDlg').hide()" />
						</f:facet>
					</p:toolbar>
					<p:panelGrid>
						<p:row>
							<p:column>
								<h:outputText value="模块" />
							</p:column>
							<p:column>
								<p:autoComplete scrollHeight="400" dropdown="true"
									value="#{problemFeedbackController.problemFeedback.module}"
									completeMethod="#{problemFeedbackController.completeModule}">
								</p:autoComplete>
							</p:column>
							<p:column>
								<h:outputText value="问题分类" />
							</p:column>
							<p:column>
								<p:autoComplete scrollHeight="400" dropdown="true"
									value="#{problemFeedbackController.problemFeedback.category}"
									completeMethod="#{problemFeedbackController.completeProblemCategory}">
								</p:autoComplete>
							</p:column>
						</p:row>
						<p:row>
							<p:column>
								<h:outputText value="问题描述" />
							</p:column>
							<p:column colspan="3">
								<h:inputTextarea
									value="#{problemFeedbackController.problemFeedback.description}"
									style="width:100%;" />
							</p:column>
						</p:row>
						<p:row>
							<p:column>
								<h:outputText value="提出时间" />
							</p:column>
							<p:column>
								<p:calendar
									value="#{problemFeedbackController.problemFeedback.proposeTime}"
									navigator="true" pattern="yyyy-MM-dd HH:mm:ss" />
							</p:column>
							<p:column>
								<h:outputText value="提出人员" />
							</p:column>
							<p:column>
								<p:inputText
									value="#{problemFeedbackController.problemFeedback.proposer}" />
							</p:column>
						</p:row>
						<p:row>
							<p:column>
								<h:outputText value="通知时间" />
							</p:column>
							<p:column>
								<p:calendar
									value="#{problemFeedbackController.problemFeedback.notifyTime}"
									navigator="true" pattern="yyyy-MM-dd HH:mm:ss" />
							</p:column>
							<p:column>
								<h:outputText value="通知人员" />
							</p:column>
							<p:column>
								<p:inputText
									value="#{problemFeedbackController.problemFeedback.notifier}" />
							</p:column>
						</p:row>
						<p:row>
							<p:column>
								<h:outputText value="处理时间" />
							</p:column>
							<p:column>
								<p:calendar
									value="#{problemFeedbackController.problemFeedback.solveTime}"
									navigator="true" pattern="yyyy-MM-dd HH:mm:ss" />
							</p:column>
							<p:column>
								<h:outputText value="处理人员" />
							</p:column>
							<p:column>
								<p:inputText
									value="#{problemFeedbackController.problemFeedback.solver}" />
							</p:column>
						</p:row>
						<p:row>
							<p:column>
								<h:outputText value="计划完成时间" />
							</p:column>
							<p:column>
								<p:calendar
									value="#{problemFeedbackController.problemFeedback.planFinishTime}"
									navigator="true" pattern="yyyy-MM-dd HH:mm:ss" />
							</p:column>
							<p:column>
								<h:outputText value="处理情况" />
							</p:column>
							<p:column>
								<h:selectOneMenu
									style="width:160px;margin-right:20px;height:30px"
									value="#{problemFeedbackController.problemFeedback.handleState}">
									<f:selectItem itemLabel="待处理" itemValue="待处理" />
									<f:selectItem itemLabel="处理中" itemValue="处理中" />
									<f:selectItem itemLabel="已处理" itemValue="已处理" />
								</h:selectOneMenu>
							</p:column>
						</p:row>
						<p:row>
							<p:column>
								<h:outputText value="原因" />
							</p:column>
							<p:column colspan="3">
								<h:inputTextarea
									value="#{problemFeedbackController.problemFeedback.problemReason}"
									style="width:100%;" />
							</p:column>
						</p:row>
						<p:row>
							<p:column>
								<h:outputText value="处理过程" />
							</p:column>
							<p:column colspan="3">
								<h:inputTextarea
									value="#{problemFeedbackController.problemFeedback.handleProcess}"
									style="width:100%;" />
							</p:column>
						</p:row>
						<p:row>
							<p:column>
								<h:outputText value="备注" />
							</p:column>
							<p:column colspan="3">
								<h:inputTextarea
									value="#{problemFeedbackController.problemFeedback.remark}"
									style="width:100%;" />
							</p:column>
						</p:row>
					</p:panelGrid>
				</p:dialog>
				<p:dialog widgetVar="uploadFileDlg" id="uploadFileDlg" modal="true" width="550" height="300">
					<p:fileUpload label="选择" uploadLabel="上传" cancelLabel="取消"
						fileUploadListener="#{problemFeedbackController.handleFileUpload}" mode="advanced" />
					<p:commandButton icon="ui-icon-disk" style="float:right;" oncomplete="PF('uploadFileDlg').hide()"
						actionListener="#{problemFeedbackController.init()}" value="关闭并刷新" update="dataTable">
					</p:commandButton>
				</p:dialog>
			</h:form>
		</div>
		<!-- 为了在下载之前判断文件是否存在，所以将下载过程截开，用js判断存在后，再下载。若不存在，则弹出提示框。 -->
		<h:form id="downloadForm">
			<p:outputLabel style="display:none;" id="fileExist" value="#{problemFeedbackController.fileExist}" />
			<p:commandButton ajax="false" id="downloadBtn" style="display:none;">
				<p:fileDownload value="#{problemFeedbackController.file}" />
			</p:commandButton>
		</h:form>
	</ui:define>
	<ui:define name="contentend">
		<script>
			function downloadFunc() {
				debugger;
				var file = document.getElementById("downloadForm:fileExist");
				if (file.innerHTML == 'true') {
					document.getElementById("downloadForm:downloadBtn").click();
				}
			}
		</script>
	</ui:define>
</ui:composition>
